package com.uiotsoft.projectmanager.common.exception;

import com.uiotsoft.projectmanager.common.constant.enums.SystemCodeType;
import com.uiotsoft.projectmanager.common.entity.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 异常处理器
 *
 * @author liupengtao
 * @date 2019-04-22
 */
@RestControllerAdvice
public class RRExceptionHandler {
	
	private Logger logger = LoggerFactory.getLogger(getClass());

	/**
	 * 自定义异常
	 */
	@ExceptionHandler(RRException.class)
	public JsonResult handleRRException(RRException e){
		return JsonResult.fail(e.getCode(),e.getMessage());
	}

	/**
	 * 通用异常
	 * @param e
	 * @return
	 */
	@ExceptionHandler(Exception.class)
	public JsonResult handleException(Exception e){
		logger.error(e.getMessage(), e);
		return JsonResult.fail(SystemCodeType.SYSTEM_ERROR.getCode(),"系统错误");
	}
	
}
